package com.example.park2301.fg

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_base.entity.NoticeBeanItem
import com.example.lib_base.mvvm.BaseFragment
import com.example.lib_base.mvvm.BaseViewFragment
import com.example.park2301.R
import com.example.park2301.databinding.FragmentIndexBinding
import com.example.park2301.notice.NoticeAdapter
import com.example.park2301.notice.NoticeViewModel
import com.example.park2301.notice.OnItemClickListener
import com.example.park2301.notice.OnItemLongClickListener
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
class IndexFragment : BaseFragment<FragmentIndexBinding,NoticeViewModel>() {
    val noticeAdapter by lazy { NoticeAdapter() }
    override fun initView() {
        binding.rvGg.apply {
            adapter=noticeAdapter
            layoutManager=LinearLayoutManager(requireContext())
        }
        lifecycleScope.launch {
            vm.getNotices().collect{
                noticeAdapter.submitData(it)
            }
        }
        noticeAdapter.setOnItemClickListener(object :OnItemClickListener{
            override fun onItemClick(position: Int, item: NoticeBeanItem) {
                Log.i("xhl",item.toString())
                noticeAdapter.notifyItemRemoved(position)
            }
        })
        noticeAdapter.setOnItemLongClickListener(object :OnItemLongClickListener{
            override fun onItemLongClick(item: NoticeBeanItem): Boolean {
                Log.i("xhl",item.toString())
                return true
            }
        })
        //跳转到访客记录
        binding.fangke.setOnClickListener {
            ARouter.getInstance().build("/app/FkActivity").navigation()
        }
    }

    override fun initData() {

    }

}